package com.interview02;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Copyright (C), 2018-2020
 * FileName: MyServer
 * Author:   kongfanyu
 * Date:     2020/12/16 11:40
 */
public class MyServer {

    public static void main(String[] args) throws Exception {
        System.out.println("服务器启动中.......");
        ServerSocket serverSocket = new ServerSocket(8080);
        Socket socket = serverSocket.accept();//线程阻塞，等待连接

        String hostAddress = socket.getInetAddress().getHostAddress();
        System.out.println("欢迎你:" + hostAddress+"连接到服务器...");
        InputStream inputStream = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(inputStream);
        BufferedReader reader = new BufferedReader(isr);
        System.out.println("接收到客户端信息:" + reader.readLine());

        serverSocket.close();
    }
}
